5 const int MAXN
= 100, MAXM
= 10205;
7 int dp
[MAXN
][MAXM
+1], p
[MAXN
], v
[MAXN
];
13 while (scanf("%d %d", &m
, &n
) == 2){
20 for (int i
=0; i
<n
; ++i
) scanf("%d %d", &p
[i
], &v
[i
]);
23 for (int j
=1; j
<=m
; ++j
) dp
[0][j
] = INT_MIN
;
25 for (int i
=1; i
<n
; ++i
){
26 for (int j
=0; j
<=m
; ++j
){
27 dp
[i
][j
] = dp
[i
-1][j
];
28 if (j
- p
[i
] >= 0 && dp
[i
-1][j
-p
[i
]] >= 0){
29 dp
[i
][j
] = max(dp
[i
][j
], dp
[i
-1][j
-p
[i
]] + v
[i
]);
35 for (int j
=0; j
<=old_m
; ++j
){
36 ans
= max(ans
, dp
[n
-1][j
]);
38 for (int j
=2001; j
<=old_m
+200; ++j
){
39 ans
= max(ans
, dp
[n
-1][j
]);